package thread.consurrent;

import java.util.concurrent.Semaphore;

/**
 * @program: baseModule
 * @description:
 * @author: zhanghz001
 * @create: 2020-10-26 11:45
 **/
public class CarRun implements Runnable {
    private final Semaphore semaphore;

    public CarRun(Semaphore semaphore) {
        this.semaphore = semaphore;
    }

    @Override
    public void run() {
        try {
            semaphore.acquire();
            System.out.println(Thread.currentThread().getName() + "开始停车");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "停车结束");
            semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
